package com.yanggeng.demo.beginnerguidedemo.bean.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "IMAGE_ADDR_BEAN".
*/
public class ImageAddrBeanDao extends AbstractDao<ImageAddrBean, Long> {

    public static final String TABLENAME = "IMAGE_ADDR_BEAN";

    /**
     * Properties of entity ImageAddrBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "IMAGEID");
        public final static Property Billid = new Property(1, Long.class, "billid", false, "BILLID");
        public final static Property Address = new Property(2, String.class, "address", false, "ADDRESS");
    }

    private Query<ImageAddrBean> billBean_ImagesQuery;

    public ImageAddrBeanDao(DaoConfig config) {
        super(config);
    }
    
    public ImageAddrBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"IMAGE_ADDR_BEAN\" (" + //
                "\"IMAGEID\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"BILLID\" INTEGER," + // 1: billid
                "\"ADDRESS\" TEXT);"); // 2: address
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"IMAGE_ADDR_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ImageAddrBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long billid = entity.getBillid();
        if (billid != null) {
            stmt.bindLong(2, billid);
        }
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(3, address);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ImageAddrBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long billid = entity.getBillid();
        if (billid != null) {
            stmt.bindLong(2, billid);
        }
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(3, address);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ImageAddrBean readEntity(Cursor cursor, int offset) {
        ImageAddrBean entity = new ImageAddrBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // billid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // address
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ImageAddrBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setBillid(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setAddress(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ImageAddrBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ImageAddrBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ImageAddrBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "images" to-many relationship of BillBean. */
    public List<ImageAddrBean> _queryBillBean_Images(Long billid) {
        synchronized (this) {
            if (billBean_ImagesQuery == null) {
                QueryBuilder<ImageAddrBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Billid.eq(null));
                billBean_ImagesQuery = queryBuilder.build();
            }
        }
        Query<ImageAddrBean> query = billBean_ImagesQuery.forCurrentThread();
        query.setParameter(0, billid);
        return query.list();
    }

}
